import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      // 读操作API代理到5200端口
      '/api/Supplier/list': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      // 客户读操作API代理到5200端口
      '/api/Customer/list': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Customer/search': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Customer/statistics': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/User/login': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      // 写操作API代理到5201端口
      '/api/Supplier/add': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Supplier/update': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Supplier/delete': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      // 客户写操作API代理到5201端口
      '/api/Customer/add': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Customer/update': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      '/api/Customer/delete': {
        target: 'http://localhost:5201',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      },
      // 默认其他API请求代理到5200端口
      '/api': {
        target: 'http://localhost:5200',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path
      }
    }
  }
})
